package com.yyq.eduservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyq.eduservice.entity.EduComment;
import com.yyq.eduservice.service.EduCommentService;
import com.yyq.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author yyq
 * @since 2021-05-05
 * 评论
 *
 * １　实现获取评论
 * ２　添加评论
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu-comment")
public class EduCommentController {
    @Autowired
    private EduCommentService commentService;

    //1 添加评论
    @PostMapping("addComment")
    public R addComment(@RequestBody EduComment eduComment){
        commentService.save(eduComment);
        return R.ok();
    }

    //2 分页显示
    @GetMapping("getCommentPage/{courseId}/{pages}/{limit}")
    public R getCommentPage(@PathVariable String courseId,@PathVariable long pages,@PathVariable long limit){
        Page<EduComment> page=new Page<>(pages,limit);
        Map map =commentService.getPages(page,courseId);


        return R.ok().data(map);
    }


}

